#include "hall.h"
uint8_t state=0;
void HALLSensor_Init(void)
{
    __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_TRIGGER);
    __HAL_TIM_ENABLE_IT(&htim3, TIM_IT_UPDATE);
    HAL_TIMEx_HallSensor_Start_IT(&htim3);
}

/**
 * @brief 获取霍尔传感器的状态
 */
uint8_t get_hall_state(void)
{
    #if 0
    if(HAL_GPIO_ReadPin(hallu_GPIO_Port,hallu_Pin)!=GPIO_PIN_RESET)
    {
        state |= 0x01U << 0;
    }
    if (HAL_GPIO_ReadPin(hallv_GPIO_Port, hallv_Pin) != GPIO_PIN_RESET)
    {
        state |= 0x01U << 0;
    }
    if (HAL_GPIO_ReadPin(hallw_GPIO_Port, hallw_Pin) != GPIO_PIN_RESET)
    {
        state |= 0x01U << 0;
    }
#else
    state = (GPIOC->IDR >> 10) & 7;
    #endif
    return state;
}
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance==TIM3)
    {
        state = get_hall_state();
        usart_printf("state=%d\r\n", state);
    }
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance==TIM3)
    {

    }
}
